#include "MMA8451Q.h"

void MMA8451Q_Init()
{
//	AS1_SendBlock(Serial1,"hello",5);
//	OutData[0]=0x2A;  OutData[1]=0x01;
//	CI2C1_MasterSendBlock(I2C,OutData, 2, LDD_I2C_NO_SEND_STOP);
//	while(!DataSendedFlg);
//	DataSendedFlg=0;
//
//
//	AS1_SendBlock(Serial1,"hello",5);
//	OutData[0]=0x0D;
//	CI2C1_MasterSendBlock(I2C,OutData, 1,  LDD_I2C_NO_SEND_STOP);
//	while(!DataSendedFlg);
//	DataSendedFlg=0;
//
//	AS1_SendBlock(Serial1,"hello",5);
//	//OutData[0]=0x1A;
//	CI2C1_MasterReceiveBlock(I2C,&MMA8451_ID, 1,  LDD_I2C_SEND_STOP);
//	while(!DataReceivedFlg);
//	DataReceivedFlg=0;

	int i=500;
	OutData[0]=0x2A;  OutData[1]=0x01;
	CI2C1_MasterSendBlock(I2C,OutData, 2, LDD_I2C_SEND_STOP);
	while(!DataSendedFlg&&(i--));
	DataSendedFlg=0;

	i=500;
	OutData[0]=0x0D;
	CI2C1_MasterSendBlock(I2C,OutData, 1,  LDD_I2C_NO_SEND_STOP);
	while(!DataSendedFlg&&(i--));
	DataSendedFlg=0;

	i=500;
	CI2C1_MasterReceiveBlock(I2C,&MMA8451_ID, 1,  LDD_I2C_SEND_STOP);
	while(!DataReceivedFlg&&(i--));
	DataReceivedFlg=0;

}

void MMA8451Q_read()
{
		OutData[0]=0x01;
		CI2C1_MasterSendBlock(I2C,OutData, 1,  LDD_I2C_NO_SEND_STOP);
		int i=500;
		while(!DataSendedFlg&&(i--));
		DataSendedFlg=0;
		if(i=0)
		{
			DataRightFlg=0;
		}

		CI2C1_MasterReceiveBlock(I2C,InData, 6,  LDD_I2C_SEND_STOP);
		i=500;
		while(!DataReceivedFlg&&(500));
		DataReceivedFlg=0;
		if(i=0)
		{
			DataRightFlg=0;
		}
}
















